<template>
    <van-nav-bar
    :title="$forceUpdate.meta.title"
    v-show="$forceUpdate.meta.isShowNav"
    @click-left="onClickLeft"
    :left-arrow="$forceUpdate.meta.isShowBack"
    fixed
    aria-placeholder=""
    style="height: 46px;"
    ></van-nav-bar>
    <router-view></router-view>
    <TabBar v-if="isShowTabbar"></TabBar>
</template>

<script setup>
import TabBar from './components/TabBar.vue';
import { useRoute } from 'vue-router';
import { ref , watch,onMounted } from 'vue'
import { useRouter } from 'vue-router';
import { getUser } from './api'
import useUser from './stores/user';

const route = useRoute()
const isShowTabbar = ref(true)
const {user,updateUser} = useUser()
const router = useRouter()

onMounted(() => {
    if(user.isLogin) {
        loadUser()
    }
})
const loadUser = async () => {
    const data = await getUser()
    updateUser({
        isLogin:true,
        username:data.username,
        avatar:data.avatar
    })
}

const onClickLeft = () => {
    if(history.length >1) {
        router.back()
    }else {
        router.push({name:'home'})
    }
}

watch(
    () => route.meta,
    val => {
        isShowTabbar.value = val.isTab
    }
)
</script>

<style>

#app {
    color: #2c3e50;
    line-height: 24px;
    --van-nav-bar-background:#FF8000;
    --van-nav-bar-title-text-color:#fff;
    --van-nav-bar-icon-color:#fff;
}
</style>